package android.zhcs.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NavUtils;

import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.MediaController;
import android.zhcs.myapplication.databinding.ActivityMainActivity2spxqBinding;

public class MainActivity2spxq extends AppCompatActivity {
    private static int sp1;
    private static int pd;
    private static String name1;
    public static void start(Context c,int sp,String name,int a) {
        Intent intent = new Intent(c, MainActivity2spxq.class);
        c.startActivity(intent);
        sp1 = sp;
        pd = a;
        name1 = name;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        finish();
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(name1);
        ActivityMainActivity2spxqBinding binding = ActivityMainActivity2spxqBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        Log.e("TAG", "android:resource://" + getPackageName() + "/" + sp1);
        if(pd == 0){
            binding.sp.setVisibility(View.VISIBLE);
            binding.sp.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + sp1));
            MediaController mediaController = new MediaController(this);
            binding.sp.setMediaController(mediaController);
            binding.sp.start();
            binding.sp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaPlayer) {
                    finish();
                }
            });
        }else{
            binding.tp.setVisibility(View.VISIBLE);
            binding.tp.setImageResource(sp1);
        }

    }
}